package com.swt.gap.controller;

import com.swt.gap.model.entity.ResultTemplate;
import com.swt.gap.service.ResultTemplateService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = " 战果模板 ,旧版,废弃")
@RestController
@RequestMapping("/result-model")
@Slf4j
@Deprecated
public class ResultTemplateController {

    private final ResultTemplateService resultTemplateService;

    public ResultTemplateController(ResultTemplateService resultTemplateService) {
        this.resultTemplateService = resultTemplateService;
    }

    @PostMapping
    @ApiOperation(value = "新增战果模板", notes = "新增战果模")
    @ApiImplicitParam(name = "resultTemplate", dataType = "ResultTemplate",paramType = "body", value = "模板信息")
    @ApiResponses({@ApiResponse(code = 201, message = "添加成功")})
    public ResponseEntity<Integer> addResultTemplate(@RequestBody ResultTemplate resultTemplate){
        return ResponseEntity.ok(resultTemplateService.addResultTemplate(resultTemplate));
    }

    @GetMapping("/{templateId}")
    @ApiOperation(value = "获取单个战果模板", notes = "获取战果模板")
    @ApiImplicitParam(name = "templateId", dataType = "Integer",paramType = "path", value = "模板Id")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = ResultTemplate.class)})
    public ResponseEntity<ResultTemplate> getResultTemplate(@PathVariable Integer templateId){
        return ResponseEntity.ok(resultTemplateService.getResultTemplate(templateId));
    }

    @GetMapping
    @ApiOperation(value = "获取全部战果模板", notes = "获取全部战果模板")
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = ResultTemplate.class, responseContainer = "List")})
    public ResponseEntity<List<ResultTemplate>> listAllResultTemplate(){
        return ResponseEntity.ok(resultTemplateService.listAllResultTemplate());
    }

    @PutMapping("/{templateId}")
    @ApiOperation(value = "修改战果模板", notes = "修改战果模板")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "templateId", dataType = "Integer",paramType = "path", value = "模板Id"),
        @ApiImplicitParam(name = "resultTemplate", dataType = "ResultTemplate",paramType = "body", value = "模板信息")
    })
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = ResultTemplate.class)})
    public ResponseEntity<ResultTemplate> updateResultTemplate(@PathVariable Integer templateId,
                                                               @RequestBody ResultTemplate resultTemplate){
        resultTemplate.setTemplateId(templateId);
        resultTemplateService.updateResultTemplate(resultTemplate);
        return ResponseEntity.ok(resultTemplate);
    }

    @DeleteMapping("/{templateId}")
    @ApiOperation(value = "删除战果模板", notes = "删除战果模板")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "templateId", dataType = "Integer",paramType = "path", value = "模板Id"),
     })
    @ApiResponses({@ApiResponse(code = 200, message = "ok", response = Integer.class)})
    public ResponseEntity<Integer> deleteResultTemplate(@PathVariable Integer templateId){
        return ResponseEntity.ok(resultTemplateService.deleteResultTemplate(templateId));
    }
}
